package com.ckzp.core.json;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.ckzp.core.Results;
import com.ckzp.core.util.StringUtil;

import java.util.HashMap;

/**
 * Created by 51594 on 2022/7/28.
 */
public class Jmode extends JSONObject {

    /**
     * @return
     */
    public static Jmode n() {
        return new Jmode();
    }


    /**
     * @return
     */
    public static Jmode n(Results results) {
        Jmode jm = new Jmode();
        jm.set("status", results.getCode()).set("info", results.getMsg());
        return jm;
    }

    /**
     * @param key
     * @param values
     * @return
     */
    public Jmode set(String key, Object values) {
        put(key, values);
        return this;
    }

    public int getInt(String key) {
        return StringUtil.getInt(String.valueOf(get(key)), 0);
    }


    public String getStr(String key) {
        return String.valueOf(get(key));
    }


    public Jmode getJmode(String key) {
        Object value = get(key);
        if (value == null) return Jmode.n();
        return JSONUtil.toBean(String.valueOf(value), Jmode.class);
    }

    /**
     * @return
     */
    public String toJson() {
        return JsonUtil.toJsonString(this);
    }

    public String toSecretJson() {
        return JsonUtil.toJsonString(this);
    }

    public String toString() {
        return super.toString();
    }
}
